// 链接桩标签
<template>
  <el-button @click="graphAddPort" type="primary" style="margin: 10px"
    >创建链接桩</el-button
  >
  <div id="container"></div>
</template>

<script lang="ts" setup>
import { ElMessage } from "element-plus";
import { Graph, DataUri, Shape } from "@antv/x6";
import { onMounted, ref } from "vue";

let graph = null;

const graphAddPort = () => {
  ElMessage({
    message: "创建链接桩",
    type: "success",
  });
  graph.addNode({
    x: 60,
    y: 60,
    width: 160,
    height: 80,
    label: "Rect With Ports",
    ports: {
      groups: {
        group1: {
          attrs: {
            circle: {
              r: 6,
              magnet: true,
              stroke: "#31d0c6",
              strokeWidth: 2,
              fill: "#fff",
            },
          },
        },
      },
      items: [
        {
          id: "port1",
          group: "group1",
          attrs: {
            text: {
              // 标签选择器
              text: "port1", // 标签文本
            },
          },
        },
        {
          id: "port2",
          group: "group1",
          attrs: {
            text: {
              // 标签选择器
              text: "port2", // 标签文本
            },
          },
        },
        {
          id: "port3",
          group: "group1",
          attrs: {
            text: {
              // 标签选择器
              text: "port2", // 标签文本
            },
          },
        },
      ],
    },
  });
};

const renderGraph = () => {
  graph = new Graph({
    container: document.getElementById("container"),
    width: 800,
    height: 600,
    panning: true,
    mousewheel: true,
    // 设置画布背景颜色
    background: {
      color: "#F2F7FA",
    },
  });

  //创建流程图数据
  const data = {};

  graph.fromJSON(data); // 渲染元素
  graph.centerContent(); // 居中显示
};

onMounted(() => {
  renderGraph();
});
</script>
